package com.tsvetanv.data.binding.nested.collections.list;

import junit.framework.TestCase;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.nested.NestedListStringCommandBean;

public class NestedListStringBindTest extends TestCase {
	private NestedListStringCommandBean bean;
	private ServletRequestDataBinder binder;
	private MockHttpServletRequest request;

	@Override
	protected void setUp() throws Exception {
		bean = new NestedListStringCommandBean();
		binder = new ServletRequestDataBinder(bean, "beanName");
		request = new MockHttpServletRequest();
	}

	public void testNestedListStringBind() {
		request.addParameter("strings[2]", "ala-bala");
		request.addParameter("strings[0]", "portokala");

		binder.bind(request);

		assertEquals("portokala", bean.getStrings().get(0));
		assertEquals("ala-bala", bean.getStrings().get(2));
		assertNull(bean.getStrings().get(1));
	}
}
